<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Translate
 *
 * @author Sebastian
 */
class Common_Translate extends Zend_Translate
{
    public function __constructor($adapter,$data,$locale = null, array $options = array())
	{
		parent::__construct($adapter,$data,$locale,$options);
	}

	public function _($messageId, array $data = array() )
	{

		$adapter = parent::getAdapter();
		$translate = $adapter->_($messageId, $locale);

		if( !empty( $data ) )
		{
			foreach($data as $k=>$v)
			{
				$translate = str_replace("%$k%",$v,$translate);
			}
		}

		return $translate;
	}

    /**
     * Metodos estaticos
     */
    public static function getDefaultDictionary($lang)
	{
		return new Common_Translate('tmx', SYSTEM_PATH.'/library/Common/Translate/translations/default.xml', "$lang");
	}

	public static function getFormDictionary($lang)
	{
		return new Common_Translate('tmx', SYSTEM_PATH.'/library/Common/Translate/translations/form.tmx', "$lang");
	}

	public static function getTranslateOf($key, $lang)
	{
		$t = self::getDefaultDictionary($lang);

		return $t->_($key);
	}

    public static function __($key)
    {
        return self::getTranslateOf($key, self::getLanguage() );
    }

	public static function getLanguage()
	{
		return Zend_Registry::get("SYSTEM_ACTIVE_LANGUAGE");
	}

	public static function setLanguage($language)
	{
		Zend_Registry::set("SYSTEM_ACTIVE_LANGUAGE",$language);
	}
}
?>
